
//果然如果是碰撞的话会和小球碰撞
let GameControl =require("GameControl");
cc.Class({
    extends: cc.Component,

    properties: {

        propName:"",
         isDrop:false,
        dropSpeed:{
            default:cc.Vec2.ZERO,
        },
        dropA:50,//下落加速度


        //双倍分数时间
        doubleTime:10,

        //速度设置
        addSpeedValue:300,
        speedTime:10,
        //长度
        addLength:100,
        lengthTime:10,
        //变大
        biggerTime:10,
        //机关枪时间
        machineTime:10,
    },

    SendProp(pname)
    {
        let yValue =cc.randomMinus1To1()*500;
        let xValue =cc.randomMinus1To1()*500;

        let useValue =new cc.Vec2(xValue,yValue);

        this.propName =pname;

        this.dropSpeed =useValue;

        this.isDrop =true;
    },


    onCollisionEnter: function (other, self) {

        if(other.node.name ==="Bar"){
            //cc.error(this.propName);

            switch(this.propName){

                case "ExplodeProp"://爆炸就不需要了，爆炸是直接触发

                    break;
                case "ScoreDoubleProp"://双倍分数
                    GameControl.instance.scoreCtl.ScoreDouble(this.doubleTime);
                    break;
                case "AddBarSpeedProp"://增加 滑动版速度
                    GameControl.instance.BarCtl.AddSpeed(this.addSpeedValue,this.speedTime);
                    break;
                case "DelBarSpeedProp"://减小 速度
                    GameControl.instance.BarCtl.DelSpeed(this.addSpeedValue,this.speedTime);
                    break;
                case "AddBarLengthProp"://增加 滑动版长度
                    GameControl.instance.BarCtl.AddLength(this.addLength,this.lengthTime);
                    break;
                case "DelBarLengthProp"://减少 长度
                    GameControl.instance.BarCtl.DelLength(this.addLength,this.lengthTime);
                    break;
                case "AddBallBiggerProp"://增加 球的体积
                    GameControl.instance.ballCtl.AddBallBiger(this.biggerTime);
                    break;
                case "DoubleBallProp"://变成双倍的球
                    GameControl.instance.ballCtl.AddDoubleBall();
                    break;
                case "MachineGun"://开启机枪
                    GameControl.instance.BarCtl.AddMachineGun(this.machineTime);
                    break;
                case "LuckScore"://幸运积分

                    break;
                case "BossBall"://超大球
                    GameControl.instance.scoreCtl.AddScore(10);
                    break;

            }
            this.node.destroy();
        }

    },
    update (dt) {//v=at

        if(this.isDrop){

            this.dropSpeed.y-=this.dropA;
            // if(this.dropSpeed.y>0)
            // {
            //     this.dropSpeed.y-=this.dropA;
            // }else{
            //     this.dropSpeed.y-=this.dropA;
            // }
            if(this.node.x>1080)
            {
                this.dropSpeed.x =(-this.dropSpeed.x);
                cc.log("改变方向"+this.dropSpeed);
            }else if(this.node.x<0){
                this.dropSpeed.x =(-this.dropSpeed.x);
            }
            this.node.x+=dt*this.dropSpeed.x;
            this.node.y+=dt*this.dropSpeed.y;

        }


        //cc.log(this.node.y);
        ///世界坐标（不是Canvas下的坐标）
        if(this.node.y<0){
            this.node.destroy();

        }
    },
});
